package encome.work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import encome.work.dao.HelpSeeker;
import encome.work.mapper.HelpSeekerMapper;
import encome.work.service.HelpSeekerService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class HelpSeekerServiceImpl extends ServiceImpl<HelpSeekerMapper, HelpSeeker> implements HelpSeekerService {

    @Resource
    private HelpSeekerMapper helpSeekerMapper;


    @Override
    public void add(HelpSeeker helpseeker) {
        helpSeekerMapper.insert(helpseeker);
    }

    @Override
    public void update(HelpSeeker helpseeker) {
        helpSeekerMapper.updateById(helpseeker);
    }

    @Override
    public void delete(Long id) {
        helpSeekerMapper.deleteById(id);
    }

    @Override
    public Page<HelpSeeker> findPage(HelpSeeker helpseeker, Integer page, Integer pageSize) {
        Page<HelpSeeker> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<HelpSeeker> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(helpseeker.getContent()),
                HelpSeeker::getContent, helpseeker.getContent());
        return helpSeekerMapper.selectPage(pageInfo, queryWrapper);
    }

    @Override
    public HelpSeeker findById(Long id) {
        return helpSeekerMapper.selectById(id);
    }

    @Override
    public Page<HelpSeeker> findPage(Integer page, Integer pageSize) {
        Page<HelpSeeker> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<HelpSeeker> queryWrapper = new LambdaQueryWrapper<>();
        return helpSeekerMapper.selectPage(pageInfo, queryWrapper);
    }
}
